<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改代码模版')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-template-edit" th:object="${genTemplate}">
            <h4 class="form-header h4">代码模版信息</h4>
            <input name="templateId" th:field="*{templateId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">模版名称：</label>
                <div class="col-sm-8">
                    <input name="templateName" th:field="*{templateName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">模版描述：</label>
                <div class="col-sm-8">
                    <input name="templateDesc" th:field="*{templateDesc}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">模版根目录：</label>
                <div class="col-sm-8">
                    <input name="templateRoot" th:field="*{templateRoot}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">模版功能类型：</label>
                <div class="col-sm-8">
                    <select name="templateFuncType" class="form-control m-b" th:with="type=${@dict.getType('template_func_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{templateFuncType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">模版引擎服务：</label>
                <div class="col-sm-8">
                    <input name="engineService" th:field="*{engineService}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否启用：</label>
                <div class="col-sm-8">
                    <select name="validYn" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{validYn}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否公开：</label>
                <div class="col-sm-8">
                    <select name="openYn" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{openYn}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
            <h4 class="form-header h4">代码模版文件信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "generator/template";
        $("#form-template-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-template-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${genTemplate.genTemplateFileList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'fileName',
                    align: 'center',
                    title: '代码文件名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].fileName' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'fileDesc',
                    align: 'center',
                    title: '代码文件描述',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].fileDesc' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'filePath',
                    align: 'center',
                    title: '模版文件路径',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].filePath' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'fileExt',
                    align: 'center',
                    title: '代码类型',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].fileExt' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'outDir',
                    align: 'center',
                    title: '输出路径',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].outDir' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'exampleUrl',
                    align: 'center',
                    title: '静态页面样例',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].exampleUrl' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createBy',
                    align: 'center',
                    title: '创建者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateBy',
                    align: 'center',
                    title: '更新者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].updateBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateTime',
                    align: 'center',
                    title: '更新时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].updateTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'remark',
                    align: 'center',
                    title: '备注',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='genTemplateFileList[%s].remark' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                fileName: "",
                fileDesc: "",
                filePath: "",
                fileExt: "",
                outDir: "",
                exampleUrl: "",
                createBy: "",
                createTime: "",
                updateBy: "",
                updateTime: "",
                remark: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>